<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017-05-27
 * Time: 10:38
 */

namespace app\admin\controller;

use think\Config;
use think\Session;

class Admin extends Base
{
    public function _initialize()
    {
        $sign_info = Session::get('sign_info');
        /*if(!$sign_info){
            $param = $this->request->get();
            if(isset($param['sign']) && !empty($param['sign'])){
                ksort($param);
                $sign = '';
                foreach($param as $key=>$val){
                    if($key != 'Sign' && $key != 'sign' && $val != ''){
                        $sign .= $key.$val;
                    }
                }
                $sign=strtoupper(md5(Config::get('app_key').$sign.Config::get('app_key')));
                if($sign != $param['sign']){
                    $this->error('签名错误');
                }

                $out_time = strtotime($param['expires_time']);
                if($out_time < time()){
                    $this->error('签名过期');
                }

                Session::set('sign_info',$param);
            }else{
                $this->error('登录失效');
            }
        }*/

        $username   = Session::get('username');
        $controller = request()->controller();

        if(!$username && $controller!='Login'){
           return $this->error('登录过期', url('login/login'));
        }
        $this->assign('username',$username);
    }

}